package com.srabbit.betafan.adapter;

import java.util.Locale;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.srabbit.betafan.R;
import com.srabbit.betafan.fragment.BaseSectionFragment;
import com.srabbit.betafan.fragment.HomeSectionFragment;
import com.srabbit.betafan.fragment.MentionSectionFragment;
import com.srabbit.betafan.fragment.MsgSectionFragment;

public class SectionsPagerAdapter extends FragmentPagerAdapter {
	
	private Context context = null;

	public SectionsPagerAdapter(Context context, FragmentManager fm) {
		super(fm);
		this.context = context;
	}

	@Override
	public Fragment getItem(int position) {
		// getItem is called to instantiate the fragment for the given page.
		// Return a DummySectionFragment (defined as a static inner class
		// below) with the page number as its lone argument.
		
		// each tab has its own fragment
		Fragment fragment = null;
		switch(position) {
		case 0:
			fragment = new HomeSectionFragment();
			break;
		case 1:
			fragment = new MentionSectionFragment();
			break;
		case 2:
			fragment = new MsgSectionFragment();
			break;
		default:
			fragment = new HomeSectionFragment();
			break;
		}
		Bundle args = new Bundle();
		args.putInt(BaseSectionFragment.ARG_SECTION_NUMBER, position + 1);
		fragment.setArguments(args);
		return fragment;
	}

	@Override
	public int getCount() {
		// Show 3 total pages.
		return 3;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		Locale l = Locale.getDefault();
		switch (position) {
		case 0:
			return context.getString(R.string.title_section1).toUpperCase(l);
		case 1:
			return context.getString(R.string.title_section2).toUpperCase(l);
		case 2:
			return context.getString(R.string.title_section3).toUpperCase(l);
		}
		return null;
	}
}
